﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using eTMS.Controllers.KhuNhaService;
using eTMS.Controllers;
using eTMS.Commons;
namespace eTMS.Controls{
   public class ComboBoxKhuNha : ComboBoxBindingBase<KhuNhaEntity>
   {
		public ComboBoxKhuNha(){
	    }
		//Bind data to txtKhuNha
        public override void BindData(){
		    List<KhuNhaEntity>lsKhuNha = new List<KhuNhaEntity>(KhuNhaController.ListKhuNhaStatic.ToArray());
			lsKhuNha=FilterList(lsKhuNha);
		    if(IsAddChooseItem){
				KhuNhaEntity eChooseItem = new KhuNhaEntity();
				eChooseItem.TenKhuNha = Constants.CHOOSE_ITEM;
				lsKhuNha.Insert(0,eChooseItem);
			}		
		    if(IsAddAllItem){
				KhuNhaEntity eChooseItem = new KhuNhaEntity();
                eChooseItem.TenKhuNha = Constants.APP_ALL;
				lsKhuNha.Insert(0,eChooseItem);
			}
            this.DisplayMember = "TenKhuNha";
		    object currentSelected=this.SelectedValue;
		    this.ValueMember = "KhuNha_ID";
		    this.DataSource = lsKhuNha;
		    if(currentSelected==null){
				if(this.Items.Count>0){
					this.SelectedIndex=0;
				}
            }
            else{
					this.SelectedValue = currentSelected;
					if(this.SelectedValue==null){
						if(this.Items.Count>0){
						this.SelectedIndex=0;
					}
                }
            }
        }
	}
}
